package first.progr.helpstaff;

import org.openqa.selenium.By;

public class NavigationHelper extends HelperBase{

	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}
	
	public void mainPage() {
		if (! onMainPage()) {
		  findAndClick(By.xpath("(//a[@href='./'])"));
		}
	}
	
	public void groupsPage() {
		if (! onGroupsPage()) {
			findAndClick(By.xpath("(//a[@href='group.php'])"));
		}
	}
		
	public void printPhonePage() {
		if (! onPrintPhonePage()) {
			findAndClick(By.xpath("(//a[@href='view.php?all&print&phones']"));
		}
	}

    private boolean onPrintPhonePage() {
		if (driver.getCurrentUrl().contains("/view.php?all&print&phones")){
		  return true;
		}
		return false;
	}

// -----------------------------------------------------------------
	
	
	private boolean onMainPage() {
		return driver.findElements(By.id("maintable")).size() > 0;
	}
    
	private boolean onGroupsPage() {
	    if (driver.getCurrentUrl().contains("/group.php")
	    	&& driver.findElements(By.name("new")).size() > 0) {
	      return true;
	    } else {
		  return false;
	   }
	}
	
	public void newContactPage() {
		findAndClick(By.xpath("(//a[@href='edit.php'])"));
	}
}
